#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function
import sys,types
from collections import namedtuple


class color(namedtuple("_Color", ['r','g','b'])):
    def __init__(self,*c):
        self = c
    def isnear(self, other, percent = 10):
        a = 1 - percent / 100
        b = 1+ percent / 100
        return self[0] * a <= other[0] <= self[0] * b \
           and self[1] * a <= other[1] <= self[1] * b \
           and self[2] * a <= other[2] <= self[2] * b
    def avg (self):
        return (self.a + self.b + self.g) / 3
    def __eq__(self, other):
        return self.r == other.r and self.b == other.b and self.g == other.g
    def __hash__(self):
        return (self.r << 16) + (self.g << 8) + self.b

class position(namedtuple("_position", ['x','y'])):
    def __init__(self,*c):
        self = c
    def __repr__(self):
        return "{0},{1}".format(self.x,self.y)
    def __eq__(self,o):
        return self.x == o.x and self.y == o.y
    def __hash__(self):
        return (self.x << 16) + self.y

class point(object):
    def __init__(self,p,c):
        self.pos, self.pos = p,c
cc = color(1,2,3)
pp = position(43,22)

def get(link):
    from urllib import urlretrieve
    urlretrieve(link,'temp.png')

class ImgRec(object):
    """Image recognition"""
    global Image, ImageEnhance
    from PIL import Image, ImageEnhance
    def __init__(self, file="temp.jpg"):
        self.img = Image.open(file)
        if self.img.mode != 'RGB':
            self.img.convert('RGB') 
        self.pix = self.img.load()
        self.size = pix.size
        pass
    def calbg():
        a = self.pix[0,0]
        b = self.pix[self.size[0],self.size[1]];
        selftttime
        
    def _print(self):
        w, h = self.img.size
        for x in xrange(w):
            for y in xrange(h):
                r,b,g = self.pix[x,y]
                print(r,b,g,sep=',')

#get('https://passport.99fund.com/servlet/buildimageservlet?random=7681');
#im = Image.open("temp.png")
#nx, ny = im.size
#im2 = im.resize((int(nx*8), int(ny*8)), Image.BICUBIC)
#enh = ImageEnhance.Contrast(im2)
#enh.enhance(1.5)
#im2.save("temp2.png")
#
#imgx = Image.open('temp2.png')
#imgx = imgx.convert("RGBA")
#pix = imgx.load()
#for y in xrange(imgx.size[1]):
#    for x in xrange(imgx.size[0]):
#        r,b,g,a = pix[x,y]
#        if (r+b+g) / 3 > 150:
#            pix[x,y] = (255, 255, 255, 255)
#        else:
#            pix[x,y] = (0, 0, 0, 255)
#imgx.save("bw.gif", "GIF")
#original = Image.open('bw.gif')
#bg = original.resize((316, 106), Image.NEAREST)
#ext = ".tif"
#original.save("input-NEAREST" + ext)
#image = Image.open('input-NEAREST.tif')        
#print image_to_string(image)

def main(argv):
    imgrec = ImgRec()
    imgrec._print()

if __name__ == '__main__':
    sys.exit(main(sys.argv[1:]))